﻿
using MediatR;
using SqlSugar;
using Warehouse.ErrorCord;
using Warehouse.Read.Api.Actions.Command.WarehouseCategory;

namespace Warehouse.Read.Api.Actions.CommandHandel.WarehouseCategory
{
    public class GetTypeShowCommandHandle : IRequestHandler<GetTypeShowCommand, APIResult<List<Warehouse.Domain.WarehouseCategory>>>
    {
        private readonly ISqlSugarClient db;

        public GetTypeShowCommandHandle(ISqlSugarClient db)
        {
            this.db = db;
        }

        public async Task<APIResult<List<Warehouse.Domain.WarehouseCategory>>> Handle(GetTypeShowCommand request, CancellationToken cancellationToken)
        {
            APIResult<List<Warehouse.Domain.WarehouseCategory>> result = new APIResult<List<Warehouse.Domain.WarehouseCategory>>();
            var list = await db.Queryable<Domain.WarehouseCategory>().ToListAsync();
            result.Data = list;
            if (result.Data != null)
            {
                result.Code = APIEnum.Success;
                result.Msg = "查询成功";
            }
            else
            {
                result.Code = APIEnum.Fail;
                result.Msg = "查询失败";
            }
            return result;
        }

    }
}
